<?php
class Admin extends MX_Controller {

	function __construct() {
		parent::__construct();
		$this->load->database();
		$this->load->library('grocery_crud');
		$this->load->helper('url');
	}

	function _view_output($output = null) {
		$this->load->view('admin.php',$output);
	}

	

	function index() {
		
	}

	function login() {
		$this->load->view('login.php');	
	}
	
	function contacts () {
		$crud = new grocery_CRUD();
		$crud->set_table("contacts");
		$crud->columns("firstname","lastname","email","message");
		$crud->display_as("id","id")
			->display_as("firstname","Họ")
			->display_as("lastname","Tên")
			->display_as("email","Email")
			->display_as("message","Nội dung")
			->display_as("created_at","created_at");
		$crud->edit_fields("firstname","lastname","email","message");
		$crud->change_field_type("created_at", "hidden", date('Y-m-d H:i:s'));
		$crud->add_fields("firstname","lastname","email","message","created_at");
		$crud->set_subject("contacts");
		$output = $crud->render();
		$output->title = "contacts";
		$this->_view_output($output);
	}

	function galleries () {
		$crud = new grocery_CRUD();
		$crud->set_table("galleries");
		$crud->columns("title","image","caption","link");
		$crud->display_as("id","id")
			->display_as("title","Tiêu đề")
			->display_as("image","Hình ảnh")
			->display_as("caption","Ghi chú")
			->display_as("link","Liên kết")
			->display_as("status","Trạng thái")
			->display_as("order","Sắp xếp");
		$crud->edit_fields("title","image","caption","link");
		$crud->add_fields("title","image","caption","link");
		$crud->set_subject("galleries");
		$output = $crud->render();
		$output->title = "galleries";
		$this->_view_output($output);
	}

	function groups () {
		$crud = new grocery_CRUD();
		$crud->set_table("groups");
		$crud->columns("name","details");
		$crud->display_as("id","id")
			->display_as("name","Tên nhóm")
			->display_as("details","Ghi chú");
		$crud->edit_fields("name","details");
		$crud->add_fields("name","details");
		$crud->set_subject("groups");
		$output = $crud->render();
		$output->title = "groups";
		$this->_view_output($output);
	}

	function post_categories () {
		$crud = new grocery_CRUD();
		$crud->set_table("post_categories");
		$crud->columns("name","details");
		$crud->display_as("id","id")
			->display_as("name","Danh mục")
			->display_as("details","Ghi chú");
		$crud->edit_fields("name","details");
		$crud->add_fields("name","details");
		$crud->set_subject("post_categories");
		$output = $crud->render();
		$output->title = "post_categories";
		$this->_view_output($output);
	}

	function pro_categories () {
		$crud = new grocery_CRUD();
		$crud->set_table("pro_categories");
		$crud->columns("name","details");
		$crud->display_as("id","id")
			->display_as("name","Danh mục")
			->display_as("details","Ghi chú");
		$crud->edit_fields("name","details");
		$crud->add_fields("name","details");
		$crud->set_subject("pro_categories");
		$output = $crud->render();
		$output->title = "pro_categories";
		$this->_view_output($output);
	}

	function products () {
		$crud = new grocery_CRUD();
		$crud->set_table("products");
		$crud->columns("id","name","description","images","catId","price");
		$crud->display_as("id","Mã sản phẩm")
			->display_as("name","Tên sản phẩm")
			->display_as("description","Thuộc tính")
			->display_as("images","Hình ảnh")
			->display_as("catId","Danh mục")
			->display_as("price","Giá")
			->display_as("color","Màu")
			->display_as("size","Kích thước")
			->display_as("brand","Nhà sản xuất")
			->display_as("created_at","created_at");
		$crud->edit_fields("id","name","description","images","catId","price");
		$crud->change_field_type("created_at", "hidden", date('Y-m-d H:i:s'));
		$crud->add_fields("id","name","description","images","catId","price");
		$crud->set_subject("products");
		$output = $crud->render();
		$output->title = "products";
		$this->_view_output($output);
	}

	function users () {
		$crud = new grocery_CRUD();
		$crud->set_table("users");
		$crud->columns("firstname","lastname","email","password","address","phone","groupId");
		$crud->display_as("id","id")
			->display_as("firstname","Họ")
			->display_as("lastname","Tên")
			->display_as("email","Email")
			->display_as("password","Mật khẩu")
			->display_as("address","Địa chỉ")
			->display_as("phone","Số điện thoại")
			->display_as("groupId","Nhóm")
			->display_as("created_at","created_at")
			->display_as("updated_at","updated_at")
			->display_as("deleted_flg","deleted_flg");
		$crud->edit_fields("firstname","lastname","email","password","address","phone","groupId","created_at");
		$crud->change_field_type("created_at", "hidden", date('Y-m-d H:i:s'));
		$crud->change_field_type("updated_at", "hidden", date('Y-m-d H:i:s'));
		$crud->add_fields("firstname","lastname","email","password","address","phone","groupId","created_at","updated_at");
		$crud->set_subject("users");
		$output = $crud->render();
		$output->title = "users";
		$this->_view_output($output);
	}


}
?>